home *** CD-ROM | disk | FTP | other *** search
/ ADA Programming Guide / ADA Programming Guide.iso / ada_gwu / block.c < prev    next >
C/C++ Source or Header  |  1996-01-30  |  7KB  |  214 lines

  1. /*
  2.     GWAda Development Environment for 386/486 PCs   
  3.     Copyright (C) 1993, Arthur Vargas Lopes  & Michael Bliss Feldman
  4.                         vlopes@vortex.ufrgs.br mfeldman@seas.gwu.edu
  5.  
  6.     This program is free software; you can redistribute it and/or modify
  7.     it under the terms of the GNU General Public License as published by
  8.     the Free Software Foundation; version 2 of the License.    
  9.  
  10.     This program is distributed in the hope that it will be useful,
  11.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.     GNU General Public License for more details.
  14.  
  15.     You should have received a copy of the GNU General Public License
  16.     along with this program; if not, write to the Free Software
  17.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18. */
  19.  
  20. /*  block.c  */
  21.  
  22. #include <externs.h>
  23.  
  24.  
  25. void AVL_PROCESS_COPY()
  26. {
  27.     AVL_EDIT_COPY(1);
  28. }
  29.  
  30.  
  31. void AVL_REMOVE_BLOCK()
  32. {
  33.     ;
  34. }
  35.  
  36.  
  37. void AVL_EDIT_COPY(int no)
  38. {
  39.     AVL_EDIT_WINDOW_PTR w;
  40.     AVL_LINE_PTR temp, temp2, temp3;
  41.     struct rccoord old;
  42.     char new_line[(AVL_MAX_LINEL*2+10)];
  43.     char save[AVL_MAX_LINEL + 2];
  44.     int i, j, k;
  45.     if ((avl_block_first_line == NULL) ||
  46.         (avl_block_last_line == NULL)) {
  47.         AVL_ERROR("Block was not marked");
  48.         return;
  49.         }
  50.     avl_block_first_line2 =
  51.     avl_block_last_line2 = NULL;
  52.     w = &avl_windows[avl_window];
  53.     temp = w -> current_line;
  54.     if (w -> txt_col > (k = strlen(temp -> line)))
  55.         AVL_CURSOR_END();
  56.     for(i = 0; i < w -> txt_col; ++i)  /* Make first line of block */
  57.         new_line[i] = temp -> line[i];
  58.     for(j = avl_block_first_col; avl_block_first_line -> line[j] != '\0'; ++j) {
  59.         new_line[i++] = avl_block_first_line -> line[j];
  60.         if (avl_block_first_line == avl_block_last_line)
  61.             if (j == avl_block_last_col)  
  62.                 break;
  63.         }
  64.     /* First line will now be completed */
  65.     if (w -> txt_col != k)
  66.         strcpy(save,&temp -> line[w -> txt_col]);
  67.     else
  68.         strcpy(save,"");
  69.     w -> changed = 1;
  70.     if (avl_block_first_line == avl_block_last_line)  { /* Done */
  71.         for(j = w -> txt_col; temp -> line[j] != '\0'; ++j)
  72.             new_line[i++] = temp -> line[j];
  73.         new_line[i++] = '\0';
  74.         if (i >= AVL_MAX_LINEL)  
  75.              AVL_ERROR("Block's first line too long. Will truncate!");
  76.         new_line[AVL_MAX_LINEL] = '\0';
  77.         strcpy(temp -> line,new_line);
  78.         AVL_UPDATE_LINE();
  79.         return;
  80.         }
  81.     new_line[i++] = '\0';
  82.     if (i >= AVL_MAX_LINEL)  
  83.          AVL_ERROR("Block's first line too long. Will truncate!");
  84.     new_line[AVL_MAX_LINEL] = '\0';
  85.     strcpy(temp -> line,new_line);
  86.     AVL_UPDATE_LINE();
  87.     /* There is more than one line */        
  88.     temp2 = temp;
  89.     for(temp = avl_block_first_line -> next; 
  90.         temp -> previous != avl_block_last_line; 
  91.         temp = temp -> next)  {
  92.         temp3 = AVL_MAKE_LINE(temp -> line, 1);
  93.         AVL_LINK(temp3,temp2);
  94.         temp2 = temp3;
  95.         }
  96.     for(i = 0; i < avl_block_last_col; ++i)
  97.         new_line[i] = temp3 -> line[i];
  98.     new_line[i++] = '\0';
  99.     strcat(new_line,save);
  100.     if (strlen(new_line) >= AVL_MAX_LINEL)  {
  101.         AVL_ERROR("Last block's line too long. Will truncate!");
  102.         new_line[AVL_MAX_LINEL] = '\0';
  103.         }
  104.     strcpy(temp3 -> line, new_line);
  105.     i = w -> scr_row;
  106.     j = w -> scr_col;
  107.     w -> scr_col = 1;
  108.     AVL_MAKE_NUMBER();
  109.     temp3 = w -> current_line;
  110.     for(temp = w -> current_line -> next; ++(w -> scr_row) <= 24 && temp != w -> head;
  111.         temp = temp -> next) {
  112.         _settextposition(w -> scr_row,1);
  113.         w -> current_line = temp;
  114.         AVL_UPDATE_LINE();
  115.         }
  116.     w -> current_line = temp3;
  117.     w -> scr_row = i;
  118.     w -> scr_col = j;
  119.     _settextposition(i,j);
  120. }
  121.  
  122.  
  123. void AVL_CLEAR_BLOCK()
  124. {
  125.     AVL_LINE_PTR t1, t2;
  126.     avl_message[0] = '\0';
  127.     if (avl_block_first_line == NULL ||
  128.         avl_block_last_line == NULL) return;
  129.     for(t1 = avl_block_first_line; t1 != avl_block_last_line; t1 = t2) {
  130.         t2 = t1 -> next;
  131.         free(t1);
  132.         }
  133.     free(t1);
  134.     avl_block_first_line2 =
  135.     avl_block_last_line2  = NULL;
  136.     avl_block_first_line = NULL;
  137.     avl_block_last_line = NULL;
  138. }
  139.  
  140. void AVL_LINK(AVL_LINE_PTR this,AVL_LINE_PTR  at)
  141. {
  142.     this -> previous = at;
  143.     this -> next     = at -> next;
  144.     at -> next -> previous = this;
  145.     at -> next = this;
  146. }
  147.  
  148. void AVL_MAKE_BLOCK()
  149. {
  150.     AVL_LINE_PTR t1, t2, t3, temp;
  151.     int i, j;
  152.     if (avl_block_first_line -> line_no > avl_block_last_line -> line_no) { /* Swap */
  153.         temp = avl_block_first_line;
  154.         avl_block_first_line = avl_block_first_line2 = avl_block_last_line;
  155.         avl_block_last_line  = avl_block_last_line2  = temp;
  156.         i = avl_block_first_col;
  157.         avl_block_first_col = avl_block_first_col2 = avl_block_last_col;
  158.         avl_block_last_col  = i;
  159.         avl_block_last_col2 = i;
  160.         }
  161.     if (avl_block_first_line == avl_block_last_line)
  162.         if (avl_block_last_col < avl_block_first_col)  { /* Swap only cols */
  163.             i = avl_block_first_col;
  164.             avl_block_first_col = avl_block_first_col2 = avl_block_last_col;
  165.             avl_block_last_col  = avl_block_last_col2  = i;
  166.             }
  167.     t1 = AVL_MAKE_LINE(avl_block_first_line -> line,1);
  168.     t1 -> next = t1 -> previous = t1;
  169.     if (avl_block_first_line == avl_block_last_line)  {
  170.         avl_block_first_line = t1;
  171.         avl_block_last_line = t1;
  172.         return;
  173.         }
  174.     temp = avl_block_first_line -> next;
  175.     avl_block_first_line = t1;
  176.     for(; temp -> previous != avl_block_last_line;
  177.         temp = temp -> next)  {
  178.         t2 = AVL_MAKE_LINE(temp -> line,1);
  179.         AVL_LINK(t2,t1);
  180.         t1 = t2;
  181.         }
  182.     avl_block_last_line = t1;
  183. }
  184.  
  185.  
  186. void AVL_GUIDE_MBLOCK()
  187. {
  188.     if ((avl_block_first_line != NULL) && (avl_block_last_line != NULL)) 
  189.         AVL_CLEAR_BLOCK();
  190.     if (avl_block_first_line == NULL) {
  191.         avl_block_first_line = avl_windows[avl_window].current_line;
  192.         if (avl_block_first_line -> line_no == 0)  
  193.             avl_windows[avl_window].current_line = 
  194.                 avl_block_first_line = avl_block_first_line -> next;
  195.         avl_block_first_col  = avl_windows[avl_window].txt_col;
  196.         avl_block_first_line2 = avl_windows[avl_window].current_line;
  197.         avl_block_first_col2  = avl_windows[avl_window].txt_col;
  198.         strcpy(avl_message,"Now mark the block's end");
  199.         AVL_UPDATE_STATUS_LINE();
  200.         }
  201.     else {
  202.         avl_block_last_line = avl_windows[avl_window].current_line;
  203.         if (avl_block_last_line -> line_no == 0)
  204.             avl_windows[avl_window].current_line = 
  205.                 avl_block_last_line = avl_block_last_line -> previous;
  206.         avl_block_last_col  = avl_windows[avl_window].txt_col;
  207.         avl_block_last_line2 = avl_windows[avl_window].current_line;
  208.         avl_block_last_col2  = avl_windows[avl_window].txt_col;
  209.         strcpy(avl_message,"Block marked");
  210.         AVL_UPDATE_STATUS_LINE();
  211.         AVL_MAKE_BLOCK();
  212.         }
  213. }
  214.